//
//  MSBaseAlertNode.m
//  MagicSword
//
//  Created by Netease on 15/11/19.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSBaseAlertNode.h"
#import "MSShadowLabel.h"

@implementation MSBaseAlertNode {
    SKSpriteNode *_backgroundNode;
    SKSpriteNode *_closeNode;
    SKSpriteNode *_doneSprite;
    MSShadowLabel  *_doneLabel;
}

- (id)init {
    self = [super initWithColor:[UIColor clearColor] size:CGSizeMake(ScreenWidth, ScreenHeight)];
    if (self) {
        self.name = NodeName_CloseAlertNodes;
        self.zPosition = 88;
        
        _backgroundNode = [SKSpriteNode spriteNodeWithImageNamed:@"main_alert_background"];
        _backgroundNode.zPosition = 9;
        _backgroundNode.size = CGSizeMake(300, 180);
        _backgroundNode.position = CGPointMake(0, 0);
        [self addChild:_backgroundNode];
        
        float size = 30;
        float left = _backgroundNode.size.width/2-size/2-10;
        float top = _backgroundNode.size.height/2-size/2-10;
        _closeNode = [SKSpriteNode spriteNodeWithImageNamed:@"main_alert_close"];
        _closeNode.zPosition = 10;
        _closeNode.size = CGSizeMake(size, size);
        _closeNode.position = CGPointMake(left, top);
        _closeNode.name = NodeName_CloseAlertNodes;
        [self addChild:_closeNode];
        
        if (!_doneSprite) {
            _doneSprite = [SKSpriteNode spriteNodeWithImageNamed:@"main_button"];
            _doneSprite.position = CGPointMake(0, -60);
            _doneSprite.zPosition = 12;
            _doneSprite.name = NodeName_DoneWeaponAlertNodes;
            [self addChild:_doneSprite];
        }
        
        if (!_doneLabel) {
            _doneLabel = [MSShadowLabel labelNodeWithFontNamed:@"Helvetica"];
            _doneLabel.position = CGPointMake(0, -68);
            _doneLabel.zPosition = 13;
            _doneLabel.fontSize = 13;
            _doneLabel.fontColor = [UIColor whiteColor];
            [_doneLabel setShadowColor:[UIColor grayColor]];
            _doneLabel.name = NodeName_DoneWeaponAlertNodes;
            [self addChild:_doneLabel];
        }
    }
    
    return self;
}

- (void)setButtonTitle:(NSString *)title {
    [_doneLabel setText:title];
}

- (void)setButtonTitleColor:(SKColor *)color {
    [_doneLabel setFontColor:color];
}

- (void)setButtonHidden:(BOOL)hidden {
    [_doneSprite setHidden:hidden];
    [_doneLabel setHidden:hidden];
}

- (void)setButtonTop:(float)top {
    _doneSprite.position = CGPointMake(0, top);
    _doneLabel.position = CGPointMake(0, top-8);
}

@end
